<?php
$this->registerCssFile('@web/css/menu.css');
//$this->registerJsFile('@web/assets/8807eebb/jquery.js',['position' => \yii\web\View::POS_HEAD]);
?>
<style>
    .menu_lock{
        position: absolute;
        width: 100%;
        height: 585px;
        background-color:white;
        opacity:0.3;
        z-index:2;
        text-align:center;
        line-height:585px;
        color:#000000;
        display:none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
</style>
<div class = "menu_lock">请求过程中,请稍等......</div>
<div class="cf nestable-lists">
    <div class="dd" id="nestable">
        <?=\common\widgets\MenuTree::widget()?>

    </div>
    <div class="" style="border:3px solid ghostwhite;padding:20px;width: 50%;height: 300px;float: right">
        <div>
            <form class="form-horizontal" role="form">
                <div class="form-group">
                    <label for="name" class="col-sm-2 control-label">菜单名称</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="name"
                               placeholder="菜单名称">
                    </div>
                </div>
                <div class="form-group">
                    <label for="url" class="col-sm-2 control-label">链接地址</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="url"
                               placeholder="链接地址">
                    </div>
                </div>
                <div class="form-group">
                    <label for="icon_char" class="col-sm-2 control-label">菜单图标</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="icon_char"
                               placeholder="菜单图标">
                    </div>
                </div>
<!--                <div class="form-group">-->

<!--                </div>-->
            </form>
            <div class="col-sm-offset-2 col-sm-10">
                <a id="addMenu" onclick="javascript:addMenu()" class="btn btn-default">生成菜单</a>
            </div>
        </div>
    </div>
</div>
<input type="hidden" name="_csrf" id='csrf' value="<?= Yii::$app->request->csrfToken ?>">

<!--<script src="js/jquery-1.10.1.min.js"></script>-->
<!--<script src="/wx/backend/web/assets/8807eebb/jquery.js"></script>-->
<script src="js/jquery.nestable.js"></script>
<script>

    $(document).ready(function()
    {
        $('#nestable').nestable();

    });

    function addMenu()
    {
        var obj = new Object();
        obj.url = $('#url').val();
        obj.icon_char = $('#icon_char').val();
        obj.name = $('#name').val();
        var csrf  = $('#csrf').val();

        $.ajax(
            {
                url: '?r=rbac/menu/addmenu',
                type: 'post',
                async: false,
                data: {_csrf: csrf, data: obj},

                success: function (data) {
                    var re = eval('('+data+')');
                    if(re.code==200){
                        $("#nestable").html(re.data);
                    }
                }
            }
        )
    }
</script>
